import * as THREE from "three";
import axios from "axios" ;
import MyFlyLine from "../class/MyFlyLine";
import Radar from "../class/MyRadar";

export const FiveExp = {
	methods:{
		async fiveExp(){
			this.loading = true ;
			this.$parent.btnIsDis = true;

			this.getMapData("worldMap") ;

			var picArr = [
				{imgUrl:"img/relatedPhoto/Five/Latvia1.jpg",imgDesc:"北约秘书长安德斯·福格·拉斯:加2013年坚定爵士乐的士兵。"},
				{imgUrl:"img/relatedPhoto/Five/Latvia2.jpg",imgDesc:"北约秘书长雅普·德·霍普·谢弗会见拉脱维亚总统瓦尔迪斯·扎特勒斯。"},
				{imgUrl:"img/relatedPhoto/Five/Latvia3.jpg",imgDesc:"北约、爱沙尼亚、拉脱维亚和立陶宛就支持北约空中警务任务和波罗的海国家其他空中活动的空域管理安排签署协议书-从左到右:雷蒙兹·伯格马尼斯（拉脱维亚国防部长)与汉内斯Hanso(爱沙尼亚国防部长)、Juozas Olekas(立陶宛国防部长）和北约副秘书长Alexander Vershbow大使。"}
			]
			this.changePicTexture(picArr);

			await   this.loadCountryNumber(5);
			var newCameraPos, newTargetPos;
			var flagAnimation = [];
			var fontAnimation;
			var Group  = new THREE.Group();
			Group.name = "Jb"
			var resource = new THREE.Group();
			this.scene.add(Group)

			// 实例化飞线
			// 加里宁格勒

			var russiaLocate = {x:35.22376917745153,y:4.5,z:-35.208354133218094}
			var germanyMyline = new MyFlyLine(russiaLocate,{x:20.296490718974326,y:4.5,z:-28.51326545205171},30) ;
			var englandMyline = new MyFlyLine(russiaLocate,{x:2.2243222611900535,y:4.5,z:-31.816376834683876},30) ;
			var franceMyline  = new MyFlyLine(russiaLocate,{x:7.780021976128921,y:4.5,z:-18.364271903313067},30) ;
			this.flyLinesArray.push(germanyMyline)
			this.flyLinesArray.push(englandMyline)
			this.flyLinesArray.push(franceMyline)
			// 加载资源

			// 加载核弹模型
			let KaliningradLabel 	   = this.get3dLabel("加里宁格勒",false,"200px",20) ;
			let nuclearBombModel = this.gltfLoadModel("model/public/nueclearBomb/scene.gltf");
			nuclearBombModel.then((res) => {
				res.scene.scale.set(0.5,0.5,0.5);
				var nuclear = res.scene.clone();
				nuclear.name = "nuclearBomb"
				KaliningradLabel.rotateY(-(Math.PI*0.5))  ;
				nuclear.add(KaliningradLabel)
				resource.add(nuclear)
			})


			// 加载国旗
			let BulgariaLabel 	   = this.get3dLabel("保加利亚",false,"20px") ;
			var flagBulgariaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagBulgariaTexture = this.changeTexture("img/flag/Bulgaria.png") ;

			// 法国
			var franceTexture = this.changeTexture("img/flag/France.png") ;
			let franceLabel 	   = this.get3dLabel("法国",false,"20px") ;

			// 德国
			var germanyTexture	   = this.changeTexture("img/flag/WestGermany.png") ;
			let germanyLabel 	   = this.get3dLabel("德国",false,"20px") ;

			//  英国
			var englandTexture	   = this.changeTexture("img/flag/England.png") ;
			let englandLabel 	   = this.get3dLabel("英国",false,"20px") ;

			await flagBulgariaModel.then((res)=>{
				let flag = res.scene.clone();
				flagAnimation = res.animations[0];
				flag.name = "Bulgaria";
				flag.scale.set(4, 4, 4)
				flag.children[0].children[1].material.map = flagBulgariaTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;

				let franceFlag = flag.clone() ;
				let franceFlagMaterial = flag.children[0].children[1].material.clone();
				franceFlag.children[0].children[1].material = franceFlagMaterial ;
				franceFlag.children[0].children[1].material.map = franceTexture  ;
				franceFlag.add(franceLabel)
				franceFlag.name = "France"
				resource.add(franceFlag)


				let germanyFlag = flag.clone() ;
				let germanyMaterial = flag.children[0].children[1].material.clone();
				germanyFlag.children[0].children[1].material = germanyMaterial ;
				germanyFlag.children[0].children[1].material.map = germanyTexture  ;
				germanyFlag.add(germanyLabel)
				germanyFlag.name = "Germany"
				resource.add(germanyFlag)

				let englandFlag = flag.clone() ;
				let englandMaterial = flag.children[0].children[1].material.clone();
				englandFlag.children[0].children[1].material = englandMaterial ;
				englandFlag.children[0].children[1].material.map = englandTexture  ;
				englandFlag.add(englandLabel) ;
				englandFlag.name = "England"  ;
				resource.add(englandFlag)     ;

				flag.add(BulgariaLabel)
				resource.add(flag)
			})

			let EstoniaLabel 	   = this.get3dLabel("爱沙尼亚",false,"20px") ;
			var flagEstoniaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagEstoniaTexture = this.changeTexture("img/flag/Estonia.png") ;
			await flagEstoniaModel.then((res)=>{
				let flag = res.scene.clone();
				flag.name = "Estonia";
				flag.scale.set(4, 4, 4)
				// 更换材质
				flag.children[0].children[1].material.map = flagEstoniaTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(EstoniaLabel)
				resource.add(flag)
			})

			let LatviaLabel 	   = this.get3dLabel("拉脱维亚",false,"20px") ;
			var flagLatviaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagLatviaTexture = this.changeTexture("img/flag/Latvia.png") ;
			await flagLatviaModel.then((res)=>{
				let flag = res.scene.clone();
				flag.name = "Latvia";
				flag.scale.set(4, 4, 4)
				// 更换材质
				flag.children[0].children[1].material.map = flagLatviaTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(LatviaLabel)
				resource.add(flag)
			})

			// 加载资源
			let LithuaniaLabel 	   = this.get3dLabel("立陶宛",false,"20px") ;
			var flagLithuaniaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagLithuaniaTexture = this.changeTexture("img/flag/Lithuania.png") ;
			await flagLithuaniaModel.then((res)=>{
				let flag = res.scene.clone();
				flagAnimation = res.animations[0];
				flag.name = "Lithuania";
				flag.scale.set(4, 4, 4)
				flag.children[0].children[1].material.map = flagLithuaniaTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(LithuaniaLabel)
				resource.add(flag)
			})

			let RomaniaLabel 	   = this.get3dLabel("罗马尼亚",false,"20px") ;
			var flagRomaniaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagRomaniaTexture = this.changeTexture("img/flag/Romania.png") ;
			await flagRomaniaModel.then((res)=>{
				let flag = res.scene.clone();
				flag.name = "Romania";
				flag.scale.set(4, 4, 4)
				// 更换材质
				flag.children[0].children[1].material.map = flagRomaniaTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(RomaniaLabel)
				resource.add(flag)
			})

			let SlovakiaLabel 	   = this.get3dLabel("斯洛伐克",false,"20px") ;
			var flagSlovakiaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagSlovakiaTexture = this.changeTexture("img/flag/Slovakia.png") ;
			await flagSlovakiaModel.then((res)=>{
				let flag = res.scene.clone();
				flag.name = "Slovakia";
				flag.scale.set(4, 4, 4)
				// 更换材质
				flag.children[0].children[1].material.map = flagSlovakiaTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(SlovakiaLabel)
				resource.add(flag)
			})

			let SloveniaLabel 	   = this.get3dLabel("斯洛文尼亚",false,"20px") ;
			var flagSloveniaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagSloveniaTexture = this.changeTexture("img/flag/Slovenia.png") ;
			await flagSloveniaModel.then((res)=>{
				let flag = res.scene.clone();
				flag.name = "Slovenia";
				flag.scale.set(4, 4, 4)
				// 更换材质
				flag.children[0].children[1].material.map = flagSloveniaTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(SloveniaLabel)
				resource.add(flag)
			})

			let RussiaLabel 	   = this.get3dLabel("俄罗斯",false,"20px") ;
			var flagRussiaModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagRussiaTexture = this.changeTexture("img/flag/Russia.png") ;
			await flagRussiaModel.then((res)=>{
				let flag = res.scene.clone();
				flag.name = "Russia";
				flag.scale.set(4, 4, 4)
				// 更换材质
				flag.children[0].children[1].material.map = flagRussiaTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(RussiaLabel)
				resource.add(flag)
			})

			var fourExpDate = this.gltfLoadModel("model/date/5-20040329/scene.gltf")
			await fourExpDate.then((res) => {
				let font  =  res.scene ;
				font.scale.set(10, 10, 10) ;
				fontAnimation = res.animations[0] ;
				font.name="20040329"
				resource.add(font)
			})

			var nuclearModel = this.gltfLoadModel("model/public/nueclearBomb/scene.gltf")
			await nuclearModel.then((res) => {
				let obj  =  res.scene ;
				obj.scale.set(10, 10, 10) ;
				obj.name="nuClearBomb"
				resource.add(obj)
			})
			this.loading = false

			///////////////////////////////////////////////////////////////////////////
			this.fifthPrompText();
			this.$refs.Lines.src = "music/lines/fiveexp/5-1.mp3" ;
			this.$refs.Lines.play();
			newCameraPos = {
				x:71.62893058789992,
				y:67.35971456848993,
				z:94.5275335763066
			}
			newTargetPos = {
				x:40.18430232851236,
				y:9,
				z:-15.913453502956859
			}

			this.animateCamera(this.camera.position, this.controls.target, newCameraPos, newTargetPos, 3000)

			setTimeout(()=>{
				let font = resource.getObjectByName("20040329");
				font.position.set(39.94000981885203,20,-60.96886182878523)
				this.onceActionPlay(fontAnimation,font)
				Group.add(font)
			},500)

			setTimeout(()=>{
				let flag = resource.getObjectByName("Slovenia");
				flag.position.set(24.06867187082888,9,-16.551665516990205);
				this.onceActionPlay(flagAnimation,flag)
				this.colorMap("Slovenia",this.myColor.newNatoArea);
				Group.add(flag)
			},4000)

			setTimeout(()=>{
				let flag = resource.getObjectByName("Estonia");
				flag.position.set(39.94000981885203,9,-45.96886182878523);
				this.onceActionPlay(flagAnimation,flag)
				this.colorMap("Estonia",this.myColor.newNatoArea);
				Group.add(flag)
			},9000)

			setTimeout(()=>{
				let flag = resource.getObjectByName("Latvia");
				flag.position.set(39.81290365622752,9,-39.95964097339821);
				this.onceActionPlay(flagAnimation,flag)
				this.colorMap("Latvia",this.myColor.newNatoArea);
				Group.add(flag)
			},10000)

			setTimeout(()=>{
				let flag = resource.getObjectByName("Lithuania");
				flag.position.set(37.77509518372291,9,-37.43094183948501);
				this.onceActionPlay(flagAnimation,flag);
				this.colorMap("Lithuania",this.myColor.newNatoArea);
				Group.add(flag)
			},11000)

			setTimeout(()=>{
				let flag = resource.getObjectByName("Slovakia");
				flag.position.set(31.735501434542996,9,-22.305621009685726);
				this.onceActionPlay(flagAnimation,flag)
				this.colorMap("Slovakia",this.myColor.newNatoArea);
				Group.add(flag)
			},14000)



			setTimeout(()=>{
				let flag = resource.getObjectByName("Romania");
				flag.position.set(40.18430232851236,9,-15.913453502956859);
				this.onceActionPlay(flagAnimation,flag)
				this.colorMap("Romania",this.myColor.newNatoArea);
				Group.add(flag)
			},15500)

			setTimeout(()=>{
				let flag = resource.getObjectByName("Bulgaria");
				flag.position.set(39.732953572271086,9,-9.609507643148623);
				this.onceActionPlay(flagAnimation,flag)
				this.colorMap("Bulgaria",this.myColor.newNatoArea);
				Group.add(flag)
			},16500)

			setTimeout(()=>{
				let flag = resource.getObjectByName("Russia");
				flag.position.set(60.848673730019456,9,-30.741660839248752);
				this.onceActionPlay(flagAnimation,flag)

				this.map.children.forEach((item) => {
					if (item.properties.name == "Russia") {
						item.children.forEach((area) => {
							if (area.type == "Mesh") {
								area.material.color.set('#ff0000')
							}
						})
					}
				})
				Group.add(flag)
			},19000)


			/////////////////////  后半段动画    ///////////////////////////////
			setTimeout(()=>{
				this.$refs.Lines.src = "music/lines/fiveexp/5-2.mp3" ;
				this.$refs.Lines.play();



				setTimeout(()=>{
					var countryArray = ["Slovenia","Estonia","Latvia","Lithuania","Slovakia","Romania","Bulgaria"];
					for (let i = 0; i < countryArray.length; i++) {
						let country = Group.getObjectByName(countryArray[i]);
						let newPos  = country.position.clone();
						newPos.y = -20
						this.recedingModel(country,country.position,newPos,2000)
					}

					let newCameraPos = {
						x:55.497668553317624,
						y:18.41006724021699,
						z:-7.362606480437371
					}

					let newTargetPos = {
						x:37.77509518372291,
						y:9,
						z:-37.43094183948501
					}
					this.animateCamera(this.camera.position, this.controls.target, newCameraPos, newTargetPos, 3000)

					let nuclear = resource.getObjectByName("nuclearBomb");
					nuclear.rotateY(Math.PI*0.5)
					nuclear.position.set(35,4,-36)
					Group.add(nuclear)
				},4000)

				setTimeout(()=>{
					let newCameraPos = {
						x:108.20874499412693,
						y:88.68344564991324,
						z:104.40835094224417
					}

					let newTargetPos = {
						x:37.77509518372291,
						y:9,
						z:-37.43094183948501
					}
					this.animateCamera(this.camera.position, this.controls.target, newCameraPos, newTargetPos, 3000)
				},7000)
			},20000)

			setTimeout(()=>{
				Group.add(germanyMyline.group)
				this.colorMap("Germany",this.myColor.focusArea);

				var germanyFlag = resource.getObjectByName("Germany");
				germanyFlag.position.set(18.296490718974326,9,-33.51326545205171)
				Group.add(germanyFlag)
				this.onceActionPlay(flagAnimation,germanyFlag)
			},28000)

			setTimeout(()=>{
				Group.add(englandMyline.group)
				this.colorMap("United Kingdom",this.myColor.focusArea);

				var englandFlag = resource.getObjectByName("England");
				englandFlag.position.set(0,9,-37.816376834683876)
				Group.add(englandFlag)
				this.onceActionPlay(flagAnimation,englandFlag)
			},29000)

			setTimeout(()=>{
				Group.add(franceMyline.group)
				this.colorMap("France",this.myColor.focusArea);

				var franceFlag = resource.getObjectByName("France");
				franceFlag.position.set(7.780021976128921,9,-23.364271903313067)
				Group.add(franceFlag)
				this.onceActionPlay(flagAnimation,franceFlag)

			},30000)

			setTimeout(()=>{
				let newCameraPos = {
					x:70.4519417752902,
					y:33.05157366368019,
					z:18.89363006594513
				}

				let newTargetPos = {
					x:12.853185002970491,
					y:4.000000000000005,
					z:-24.421204128529034
				}
				this.animateCamera(this.camera.position, this.controls.target, newCameraPos, newTargetPos, 3000)
			},30000)
		},
		
	}
}